<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TeamCommunitySolution.Domain.DataLayer.Leagues.League>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
  LeagueEdit
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

  <script type="text/javascript">
    $.ui.dialog.defaults.bgiframe = true;

    $(document).ready(function() {
        $("#TeamSearch").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 500,
            width: 400,
            zIndex: 400,
            modal: true,
            buttons: {
                'Invite': function() {
                    $.post('<%= Url.Action("InviteTeam", "League") %>',
                    { teamName: $('#ToTeam').val(),
                        message: $('#InviteMessage').val(),
                        leagueId: $('#LeagueId').val()
                    });
                    //responseCallback);
                    $(this).dialog('close');
                    return false;
                },
                Cancel: function() {
                    $(this).dialog('close');
                }
            }
        });

        $("#teamSearchInitiate").click(function() {
            $("#TeamSearch").dialog('open');
            return false;
        });

        $("input#ToTeam").autocomplete('<%= Url.Action("SearchName", "Team") %>');

    });
  </script>

  <div style="float: left; width: 45%;">
    <h2>
      LeagueEdit</h2>
    <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>
    <% using(Html.BeginForm()) {%>
    <%= Html.Hidden("Id",Model.Id) %>
    <fieldset>
      <legend>League Information</legend>
      <p>
        <label for="Name">
          Name:</label>
        <%= Html.TextBox("Name", Model.Name) %>
        <%= Html.ValidationMessage("Name", "*") %>
      </p>
      <p>
        <label for="TeamSize">
          TeamSize:</label>
        <%= Html.TextBox("TeamSize", Model.TeamSize) %>
        <%= Html.ValidationMessage("TeamSize", "*") %>
      </p>
      <p>
        <label for="IsComplete">
          IsComplete:</label>
        <%= Html.CheckBox("IsComplete", Model.IsComplete) %>
        <%= Html.ValidationMessage("IsComplete", "*") %>
      </p>
      <p>
        <input type="submit" value="LeagueEdit" />
      </p>
    </fieldset>
    <% } %>
  </div>
  <div style="float: right; width: 45%;">
    <div style="float: left; width: 45%;">
      <% if(Model != null) { %>
      <button id="teamSearchInitiate" class="ui-state-default ui-corner-all">
        Invite Teams</button><br />
      <% } %>
      <br />
      <div id="searchForm">
        <% if(Model != null) {
             Html.RenderPartial("~/Views/Team/TeamSearch.ascx", Model);
           } %>
      </div>
      <table width="100%">
        <tr>
          <th>
            League Team
          </th>
        </tr>
        <%
          foreach(var item in Model.TeamList) { %>
        <tr>
          <td>
            <%= Html.ActionLink(item.Name, "Details", "Team", new { team = item.Id }, null)%>
          </td>
        </tr>
        <% }%>
      </table>
    </div>
    <div style="float: left; width: 45%;">
      <% if(Model.MeetingList != null) { %>
      <table width="100%">
        <tr>
          <th>
            League Meetings
          </th>
        </tr>
        <%
          foreach(var item in Model.MeetingList) { %>
        <tr>
          <td>
            <%= Html.ActionLink("Edit", "Edit", "LeagueMeeting", new { meeting = item.Id }, null)%>
            |
            <%= Html.ActionLink(item.Name, "Details", "LeagueMeeting", new { meeting = item.Id }, null)%>
          </td>
        </tr>
        <% }%>
      </table>
      <% } %>
    </div>
  </div>
</asp:Content>
